//
//  BannerVC.m
//  CJModileAdDemo
//
//  Created by CJ on 2022/3/7.
//

#import "BannerVC.h"
#import <CJMobileAd/CJMobileAd.h>
#import "CustomShowView.h"
#import <BUAdSDK/BUAdSDK.h>


@interface BannerVC ()<BUNativeExpressBannerViewDelegate>

@property (nonatomic,strong) BUNativeExpressBannerView *byte_bannerAd;

@property (nonatomic, strong) UIView *bannerView;

@end

@implementation BannerVC

@synthesize customView = _customView;
    
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)setupUI {
    self.title = @"Banner";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)loadAdData {
    self.byte_bannerAd = [[BUNativeExpressBannerView alloc] initWithSlotID:@"102818877" rootViewController:self adSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*50/320) interval:0];
    self.byte_bannerAd.delegate = self;
    [self.byte_bannerAd loadAdData];
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        [self loadAdData];
        return;
    }
}

- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak BannerVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark CJBannerAdDelegate
- (void)nativeExpressBannerAdViewDidLoad:(BUNativeExpressBannerView *)bannerAdView {
    NSLog(@"事件:%s", __FUNCTION__);
    CGRect frame = bannerAdView.frame;
    frame.origin.y = 88;
    frame.origin.x = 0;
    bannerAdView.frame = frame;
    [self.view addSubview:bannerAdView];
}

- (void)nativeExpressBannerAdViewWillBecomVisible:(BUNativeExpressBannerView *)bannerAdView {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressBannerAdView:(BUNativeExpressBannerView *)bannerAdView didLoadFailWithError:(NSError *_Nullable)error{
    NSLog(@"事件:%s", __FUNCTION__);
}
    
- (void)nativeExpressBannerAdViewRenderFail:(BUNativeExpressBannerView *)bannerAdView error:(NSError * __nullable)error{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressBannerAdViewDidClick:(BUNativeExpressBannerView *)bannerAdView{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressBannerAdView:(BUNativeExpressBannerView *)bannerAdView dislikeWithReason:(NSArray<BUDislikeWords *> *_Nullable)filterwords{
    NSLog(@"事件:%s", __FUNCTION__);
}

@end
